home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / HandleSettings.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  27KB  |  896 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. // include precompiled headers (if not already)
  21. #ifndef TSMORPH_H
  22. #include "TSMorph.h"
  23. #endif
  24.  
  25. /* Remove menus from all windows allowing
  26.  * them to be updated
  27.  */
  28. void
  29. RemoveMenus(void) {
  30.     if (TSMorphWnd) {
  31.         ClearMenuStrip(TSMorphWnd);
  32.     }
  33.     if (ControlWindow) {
  34.         ClearMenuStrip(Pic1.Win);
  35.         ClearMenuStrip(Pic2.Win);
  36.         ClearMenuStrip(ControlWindow);
  37.     }
  38. }
  39.  
  40. /* Add the menus back again after
  41.  * calling RemoveMenus() and updating
  42.  */
  43. void
  44. AddMenus(void) {
  45.     if (TSMorphWnd) {
  46.         ResetMenuStrip(TSMorphWnd,TSMorphMenus);
  47.     }
  48.     if (ControlWindow) {
  49.         ResetMenuStrip(ControlWindow,MyMenu);
  50.         ResetMenuStrip(Pic1.Win,MyMenu);
  51.         ResetMenuStrip(Pic2.Win,MyMenu);
  52.     }
  53. }
  54.  
  55. /* Update the save format menu items
  56.  * Parameter: remove - set to TRUE to remove and add the menus
  57.  *                         to FALSE if menus have already been removed (for lots of updates)
  58.  */
  59. void
  60. UpdateSaveFormat(BOOL remove) {
  61.     if (remove) {
  62.         RemoveMenus();
  63.     }
  64.     if (TSMorphWnd) {
  65.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
  66.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
  67.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
  68.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
  69.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
  70.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
  71.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
  72.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
  73.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
  74.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
  75.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
  76.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
  77.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
  78.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
  79.     }
  80.     if (ControlWindow) {
  81.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
  82.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
  83.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
  84.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
  85.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
  86.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
  87.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
  88.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
  89.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
  90.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
  91.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
  92.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
  93.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
  94.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
  95.     }
  96.     if (TSMorphWnd) {
  97.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
  98.     }
  99.     if (ControlWindow) {
  100.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
  101.     }
  102.     if (remove) {
  103.         AddMenus();
  104.     }
  105. }
  106.  
  107. /* Update the render mode menu items
  108.  * see UpdateSaveFormat() for parameter
  109.  */
  110. void
  111. UpdateRenderMode(BOOL remove) {
  112.     if (remove) {
  113.         RemoveMenus();
  114.     }
  115.     if (TSMorphWnd) {
  116.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
  117.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
  118.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE4)))->Flags &= ~CHECKED;
  119.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE8)))->Flags &= ~CHECKED;
  120.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE16)))->Flags &= ~CHECKED;
  121.     }
  122.     if (ControlWindow) {
  123.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
  124.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
  125.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE4)))->Flags &= ~CHECKED;
  126.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE8)))->Flags &= ~CHECKED;
  127.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE16)))->Flags &= ~CHECKED;
  128.     }
  129.     if (TSMorphWnd) {
  130.         if (RenderMode & 1) {
  131.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE1)))->Flags |= CHECKED;
  132.         }
  133.         if (RenderMode & 2) {
  134.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE2)))->Flags |= CHECKED;
  135.         }
  136.         if (RenderMode & 4) {
  137.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE4)))->Flags |= CHECKED;
  138.         }
  139.         if (RenderMode & 8) {
  140.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE8)))->Flags |= CHECKED;
  141.         }
  142.         if (RenderMode & 16) {
  143.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE16)))->Flags |= CHECKED;
  144.         }
  145.     }
  146.     if (ControlWindow) {
  147.         if (RenderMode & 1) {
  148.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE1)))->Flags |= CHECKED;
  149.         }
  150.         if (RenderMode & 2) {
  151.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE2)))->Flags |= CHECKED;
  152.         }
  153.         if (RenderMode & 4) {
  154.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE4)))->Flags |= CHECKED;
  155.         }
  156.         if (RenderMode & 8) {
  157.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE8)))->Flags |= CHECKED;
  158.         }
  159.         if (RenderMode & 16) {
  160.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE16)))->Flags |= CHECKED;
  161.         }
  162.     }
  163.     if (remove) {
  164.         AddMenus();
  165.     }
  166. }
  167.  
  168. /* Update the open mode menu items
  169.  * see UpdateSaveFormat() for parameter
  170.  */
  171. void
  172. UpdateOpenMode(BOOL remove) {
  173.     if (remove) {
  174.         RemoveMenus();
  175.     }
  176.     if (TSMorphWnd) {
  177.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
  178.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
  179.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
  180.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
  181.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
  182.     }
  183.     if (ControlWindow) {
  184.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
  185.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
  186.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
  187.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
  188.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
  189.     }
  190.     if (TSMorphWnd) {
  191.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
  192.     }
  193.     if (ControlWindow) {
  194.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
  195.     }
  196.     if (remove) {
  197.         AddMenus();
  198.     }
  199. }
  200.  
  201. /* UnZoom the image windows
  202.  * i.e. currently displayed 2x and
  203.  * want to display 1x
  204.  */
  205. void
  206. UnZoom(void) {
  207.     // Already zoomed - set number of windows resized (change window box may not work)
  208.     // see the main loop on how the messages are then handled
  209.     changedboxcount = 0;
  210.     // Copy image 1 to superbitmap and resync
  211.     BltBitMap(Pic1.ilbm->brbitmap,0,0,&(Pic1.BitMap),0,0,Pic1.ilbm->Bmhd.w,Pic1.ilbm->Bmhd.h,0xC0,0xff,NULL);
  212.     LockLayerRom(Pic1.Win->RPort->Layer);
  213.     CopySBitMap(Pic1.Win->RPort->Layer);
  214.     UnlockLayerRom(Pic1.Win->RPort->Layer);
  215.     /* Resize gadgets and window (if too big)
  216.      * Window limits are reset and points
  217.      * redrawn with IDCMP_CHANGEWINDOW
  218.      */
  219.     SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
  220.                         PGA_Total,    Pic1.ilbm->Bmhd.w,
  221.                         TAG_END);
  222.     SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
  223.                         PGA_Total,    Pic1.ilbm->Bmhd.h,
  224.                         TAG_END);
  225.     ChangeWindowBox(Pic1.Win,Pic1.Win->LeftEdge,Pic1.Win->TopEdge,
  226.                          min(Pic1.Win->Width,Pic1.ilbm->Bmhd.w+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n)),
  227.                          min(Pic1.Win->Height,Pic1.ilbm->Bmhd.h+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
  228.     // Do the same of image/window2
  229.     BltBitMap(Pic2.ilbm->brbitmap,0,0,&(Pic2.BitMap),0,0,Pic2.ilbm->Bmhd.w,Pic2.ilbm->Bmhd.h,0xC0,0xff,NULL);
  230.     LockLayerRom(Pic2.Win->RPort->Layer);
  231.     CopySBitMap(Pic2.Win->RPort->Layer);
  232.     UnlockLayerRom(Pic2.Win->RPort->Layer);
  233.     SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
  234.                         PGA_Total,    Pic2.ilbm->Bmhd.w,
  235.                         TAG_END);
  236.     SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
  237.                         PGA_Total,    Pic2.ilbm->Bmhd.h,
  238.                         TAG_END);
  239.     ChangeWindowBox(Pic2.Win,Pic2.Win->LeftEdge,Pic2.Win->TopEdge,
  240.                          min(Pic2.Win->Width,Pic2.ilbm->Bmhd.w+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n)),
  241.                          min(Pic2.Win->Height,Pic2.ilbm->Bmhd.h+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
  242.     // Wait till its all done (why?) and reset Zoom
  243.     WaitBlit();
  244.     Zoom = 0;
  245. }
  246.  
  247. /* Zoom the image windows
  248.  * i.e. currently displayed 1x and
  249.  * want to display 2x
  250.  */
  251. void
  252. ReZoom(void) {
  253.     /* Currently normal size
  254.      * scale image 1, set window max size
  255.      * redo gadgets and copy to superbitmap
  256.      */
  257.     BitMapScale(&(Pic1.BitScaleArgs));
  258.     WindowLimits(Pic1.Win,0,0,(Pic1.ilbm->Bmhd.w<<1)+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n),
  259.                     (Pic1.ilbm->Bmhd.h<<1)+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
  260.     SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
  261.                         PGA_Total,    Pic1.ilbm->Bmhd.w<<1,
  262.                         TAG_END);
  263.     SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
  264.                         PGA_Total,    Pic1.ilbm->Bmhd.h<<1,
  265.                         TAG_END);
  266.     LockLayerRom(Pic1.Win->RPort->Layer);
  267.     CopySBitMap(Pic1.Win->RPort->Layer);
  268.     UnlockLayerRom(Pic1.Win->RPort->Layer);
  269.     // Same for image 2
  270.     BitMapScale(&(Pic2.BitScaleArgs));
  271.     WindowLimits(Pic2.Win,0,0,(Pic2.ilbm->Bmhd.w<<1)+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n),
  272.                     (Pic2.ilbm->Bmhd.h<<1)+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
  273.     SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
  274.                         PGA_Total,    Pic2.ilbm->Bmhd.w<<1,
  275.                         TAG_END);
  276.     SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
  277.                         PGA_Total,    Pic2.ilbm->Bmhd.h<<1,
  278.                         TAG_END);
  279.     LockLayerRom(Pic2.Win->RPort->Layer);
  280.     CopySBitMap(Pic2.Win->RPort->Layer);
  281.     UnlockLayerRom(Pic2.Win->RPort->Layer);
  282.     /* Reset Zoom, Check new size gadgets,
  283.      * and redraw all the points
  284.      */
  285.     Zoom = 1;
  286.     doNewSize(&Pic1);
  287.     doNewSize(&Pic2);
  288.     DrawAllPoints();
  289. }
  290.  
  291. /* switch the check mark of a settings menu item
  292.  * Parameters: pos        position in the settings menu
  293.  *             settings   TRUE or FALSE
  294.  *             remove     remove and add menus? see UpdateSaveFormat()
  295.  */
  296. void
  297. SwitchMenuItem(UWORD pos,BOOL setting,BOOL remove) {
  298.     if (remove) {
  299.         RemoveMenus();
  300.     }
  301.     if (TSMorphWnd) {
  302.         if (setting) {
  303.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags |= CHECKED;
  304.         }
  305.         else {
  306.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags &= ~CHECKED;
  307.         }
  308.     }
  309.     if (ControlWindow) {
  310.         if (setting) {
  311.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags |= CHECKED;
  312.         }
  313.         else {
  314.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags &= ~CHECKED;
  315.         }
  316.     }
  317.     if (remove) {
  318.         AddMenus();
  319.     }
  320. }
  321.  
  322. /* Handle Settings menu messages
  323.  * Parameters: Selection   the item number
  324.  *             pic         the current picture
  325.  */
  326. void
  327. HandleSettings(UWORD Selection,struct Picture *pic) {
  328.     ULONG OZoom;    // The old zoom mode
  329.     // switch on the selection
  330.     switch(ITEMNUM(Selection)) {
  331.     case MM_ICONS:
  332.         // Toggle Create Icons?
  333.         CreateIcons = !CreateIcons;
  334.         SwitchMenuItem(MM_ICONS,CreateIcons,TRUE);
  335.         break;
  336.     case MM_PALETTE:
  337.         // Toggle Change Palette? - Uncolor the current image if we have one
  338.         if (palette && pic) {
  339.             UnColorWindow(pic);
  340.         }
  341.         palette = !palette;
  342.         SwitchMenuItem(MM_PALETTE,palette,TRUE);
  343.         break;
  344.     case MM_ZOOM:
  345.         // Toggle Zoom?
  346.         if (ControlWindow) {
  347.             // UnZoom or ReZoom the images if open
  348.             DisableWindows(DI_Zoom);
  349.             if (Zoom) {
  350.                 UnZoom();
  351.             }
  352.             else {
  353.                 ReZoom();
  354.             }
  355.             EnableWindows();
  356.         }
  357.         else {
  358.             if (Zoom) {
  359.                 Zoom = 0;
  360.             }
  361.             else {
  362.                 Zoom = 1;
  363.             }
  364.         }
  365.         SwitchMenuItem(MM_ZOOM,Zoom,TRUE);
  366.         break;
  367.     case MM_OPENMODE:
  368.         // Set new open mode
  369.         OpenMode = SUBNUM(Selection);
  370.         UpdateOpenMode(TRUE);
  371.         break;
  372.     case MM_SCREEN:
  373.         // Get public screen name
  374.         GetAString("Public Screen",ScreenName,H_P_PS);
  375.         break;
  376.     case MM_CUSTOM:
  377.         // Get custom screen mode
  378.         GetAString("Custom Screen Mode",CustomName,H_PCUSTM);
  379.         break;
  380.     case MM_CDEPTH:
  381.         // Get custom screen depth
  382.         GetANumber("Custom Screen Depth",&CustomDepth,H_PCUSTD);
  383.         break;
  384.     case MM_SPREVIEW:
  385.         // Get preview script
  386.         GetAString("Preview Script",PreviewScript,H_P_Preview);
  387.         break;
  388.     case MM_ICONSP:
  389.         // Toggle Create prefs Icons?
  390.         CreateIconsP = !CreateIconsP;
  391.         SwitchMenuItem(MM_ICONSP,CreateIconsP,TRUE);
  392.         break;
  393.     case MM_KEEPS:
  394.         // Toggle Keep Settings?
  395.         KeepSettings = !KeepSettings;
  396.         SwitchMenuItem(MM_KEEPS,KeepSettings,TRUE);
  397.     case MM_LOADS:
  398.         // Load new settings from requester
  399.         LoadSettings(NULL);
  400.         break;
  401.     case MM_SAVES:
  402.         // Save settings to ENV: and ENVARC:
  403.         SaveSettings("ENVARC:TSMorph/TSMorph.prefs");
  404.         SaveSettings("ENV:TSMorph/TSMorph.prefs");
  405.         break;
  406.     case MM_SAVESAS:
  407.         // save settings from requester
  408.         SaveSettings(NULL);
  409.         break;
  410.     case MM_ICONSR:
  411.         // Toggle Create render Icons?
  412.         CreateIconsR = !CreateIconsR;
  413.         SwitchMenuItem(MM_ICONSR,CreateIconsR,TRUE);
  414.         break;
  415.     case MM_DX:
  416.         // Get DX
  417.         GetANumber("DX",&DX,H_P_DX);
  418.         break;
  419.     case MM_DY:
  420.         // Get DY
  421.         GetANumber("DY",&DY,H_P_DY);
  422.         break;
  423.     case MM_LOADSCRIPT:
  424.         // Get load script
  425.         GetAString("Load Script",LoadScript,H_P_LS);
  426.         break;
  427.     case MM_PRESCRIPT:
  428.         // Get pre script
  429.         GetAString("Pre Script",PreScript,H_P_PES);
  430.         break;
  431.     case MM_POSTSCRIPT:
  432.         // Get post script
  433.         GetAString("Post Script",PostScript,H_P_POS);
  434.         break;
  435.     case MM_DEPTH:
  436.         // Get depth
  437.         GetANumber("Depth",&Depth,H_P_DE);
  438.         break;
  439.     case MM_RENDERMODE:
  440.         // Set new render mode
  441.         RenderMode = 0;
  442.         if ((ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE1)))->Flags & CHECKED) {
  443.             RenderMode |= 1;
  444.         }
  445.         if ((ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE2)))->Flags & CHECKED) {
  446.             RenderMode |= 2;
  447.         }
  448.         if ((ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE4)))->Flags & CHECKED) {
  449.             RenderMode |= 4;
  450.         }
  451.         if ((ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE8)))->Flags & CHECKED) {
  452.             RenderMode |= 8;
  453.         }
  454.         if ((ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE16)))->Flags & CHECKED) {
  455.             RenderMode |= 16;
  456.         }
  457.         UpdateRenderMode(TRUE);
  458.         break;
  459.     case MM_SAVEFORMAT:
  460.         // Set new save format
  461.         SaveFormat = SUBNUM(Selection);
  462.         UpdateSaveFormat(TRUE);
  463.         break;
  464.     case MM_QUALITY:
  465.         // Get quality
  466.         GetANumber("Quality",&Quality,H_P_QU);
  467.         break;
  468.     case MM_SCREENR:
  469.         // Get render public screen
  470.         GetAString("Render Screen",ScreenNameR,H_P_PSR);
  471.         break;
  472.     case MM_ANTIALIAS:
  473.         // Toggle Anti-Alias?
  474.         AntiAlias = !AntiAlias;
  475.         SwitchMenuItem(MM_ANTIALIAS,AntiAlias,TRUE);
  476.         break;
  477.     case MM_INTEGER:
  478.         // Toggle Integer?
  479.         Integer = !Integer;
  480.         SwitchMenuItem(MM_INTEGER,Integer,TRUE);
  481.         break;
  482.     case MM_RESETD:
  483.         // Reset to default prefs
  484.         OZoom = Zoom;    // keep current zoom
  485.         if (!ControlWindow) {
  486.             // if the images are open then we can not change these
  487.             PaletteAllowed = TRUE;
  488.             ZoomAllowed = TRUE;
  489.         }
  490.         // Set all other settings to defaults
  491.         ScreenName[0] = 0;
  492.         ScreenNameR[0] = 0;
  493.         CreateIcons = TRUE;
  494.         CreateIconsR = FALSE;
  495.         CreateIconsP = TRUE;
  496.         KeepSettings = TRUE;
  497.         if (PaletteAllowed) {
  498.             palette = TRUE;
  499.         }
  500.         else {
  501.             palette = FALSE;
  502.         }
  503.         Zoom = 0;
  504.         OpenMode = OPEN_ILBM_IF_COLOURS;
  505.         SaveFormat = MI_ILBM24;
  506.         Quality = 75;
  507.         strcpy(PreScript,"Rexx/Prescript");
  508.         strcpy(PostScript,"Rexx/Postscript");
  509.         strcpy(LoadScript,"Rexx/Loadscript");
  510.         strcpy(PreviewScript,"Rexx/Preview");
  511.         DX = 0;
  512.         DY = 0;
  513.         Depth = 2;
  514.         RenderMode = 0;
  515.         CustomName[0] = 0;
  516.         CustomDepth = 4;
  517.         AntiAlias = FALSE;
  518.         Integer = FALSE;
  519.         GHelp = FALSE;
  520.         UpdateParams(OZoom);
  521.         break;
  522.     case MM_LASTS:
  523.         // Load settings from ENVARC:
  524.         LoadSettings("ENVARC:TSMorph/TSMorph.prefs");
  525.         break;
  526.     case MM_RESTORE:
  527.         // Load settings from ENV:
  528.         LoadSettings("ENV:TSMorph/TSMorph.prefs");
  529.         break;
  530.     case MM_HELP:
  531.         // Toggle Help?
  532.         GHelp = !GHelp;
  533.         SwitchMenuItem(MM_HELP,GHelp,TRUE);
  534.         break;
  535.     default:
  536.         // something else ??
  537.         break;
  538.     }
  539. }
  540.  
  541. /* Request a number from the user using reqtools.library
  542.  * Parameters: title   - title of requester
  543.  *             number  - address of number to display and get
  544.  *             HelpNum - help key if help required
  545.  */
  546. void
  547. GetANumber(char *title,ULONG *number,ULONG HelpNum) {
  548.     ULONG                     ret = 2;    // current gadget
  549.     struct AmigaGuideMsg    *agm;        // amiga guide stuff
  550.     ULONG                     signals;    // signals to wait on
  551.     struct rtHandlerInfo    *rth;        // reqtools stuff
  552.     // disable all the windows
  553.     DisableWindows(HelpNum);
  554.     // loop until Ok or Cancel pressed
  555.     while (ret == 2) {
  556.         ret = CALL_HANDLER;
  557.         if (rtGetLong(number,title,NULL,
  558.                             RT_ReqHandler,        &rth,
  559.                             RT_Window,            TSMorphWnd,
  560.                             RTGL_ShowDefault,    TRUE,
  561.                             RT_Underscore,        '_',
  562.                             RTGL_GadFmt,         handle?"_OK|_Help|_Cancel":"_OK|_Cancel", // if amigaguide then help gadget
  563.                             TAG_END) == CALL_HANDLER) {
  564.             while (ret == CALL_HANDLER) {
  565.                 if (!rth->DoNotWait) {
  566.                     // wait if possible
  567.                     signals = Wait(rth->WaitMask | ASig);
  568.                 }
  569.                 ret = rtReqHandlerA(rth,signals,NULL);
  570.                 if (ret == 2) {
  571.                     // display help if requested, 2 is only possible if help gadget is available
  572.                     help(HelpNum);
  573.                 }
  574.                 if (signals & ASig) {
  575.                     // do amigaguide stuff
  576.                       while (agm = GetAmigaGuideMsg(handle)) {
  577.                          ReplyAmigaGuideMsg(agm);
  578.                      }
  579.                  }
  580.             }
  581.         }
  582.     }
  583.     // re-enable all the windows
  584.     EnableWindows();
  585. }
  586.  
  587. /* Request a string from the user using reqtools.library
  588.  * Parameters: title   - title of requester
  589.  *             number  - address of buffer to display and get
  590.  *             HelpNum - help key if help required
  591.  * See GetANumber for comments
  592.  */
  593. void
  594. GetAString(char *title,char *buffer,ULONG HelpNum) {
  595.     ULONG                     ret = 2;
  596.     struct AmigaGuideMsg    *agm;
  597.     ULONG                     signals;
  598.     struct rtHandlerInfo    *rth;
  599.     DisableWindows(HelpNum);
  600.     while (ret == 2) {
  601.         ret = CALL_HANDLER;
  602.         if (rtGetString(buffer,127,title,NULL,
  603.                             RT_ReqHandler,        &rth,
  604.                             RT_Window,            TSMorphWnd,
  605.                             RTGL_ShowDefault,    TRUE,
  606.                             RT_Underscore,     '_',
  607.                             RTGL_GadFmt,         handle?"_OK|_Help|_Cancel":"_OK|_Cancel",
  608.                             RTGS_AllowEmpty,    TRUE,
  609.                             TAG_END) == CALL_HANDLER) {
  610.             while (ret == CALL_HANDLER) {
  611.                 if (!rth->DoNotWait) {
  612.                     signals = Wait(rth->WaitMask | ASig);
  613.                 }
  614.                 ret = rtReqHandlerA(rth,signals,NULL);
  615.                 if (ret == 2) {
  616.                     help(HelpNum);
  617.                 }
  618.                 if (signals & ASig) {
  619.                       while (agm = GetAmigaGuideMsg(handle)) {
  620.                          ReplyAmigaGuideMsg(agm);
  621.                      }
  622.                  }
  623.             }
  624.         }
  625.     }
  626.     EnableWindows();
  627. }
  628.  
  629. /* Save the current settings
  630.  * Parameters: filename - filename to save to
  631.  *                        or NULL for requester
  632.  */
  633. void
  634. SaveSettings(char *filename) {
  635.     char    *ifilename = NULL;    // the actual file name
  636.     BPTR    fh;                        // file handle
  637.     BOOL    ok = TRUE;                // Is it working?
  638.     char    buffer[65];                // buffer for records
  639.     struct DiskObject *MyDiskObject;    // The Icon
  640.     // Disable all windows
  641.     DisableWindows(DI_WaitSS);
  642.     // if no file name supplied then request a name
  643.     if (!filename) {
  644.         if (GetAFile("TSMorph.prefs","Save Settings",FILF_SAVE)) {
  645.             ifilename = TempFilename;
  646.         }
  647.     }
  648.     else {
  649.         ifilename = filename;
  650.     }
  651.     // if we now a file name
  652.     if (ifilename) {
  653.         // try and open the file
  654.         if (fh = Open(ifilename,MODE_NEWFILE)) {
  655.             // save all TSMorph settings
  656.             FPuts(fh,";TSMorph parameters\n");
  657.             FPuts(fh,"CREATEICONS=");
  658.             FPuts(fh,CreateIcons?"YES\n":"NO\n");
  659.             FPuts(fh,"CHANGEPALETTE=");
  660.             FPuts(fh,(!PaletteAllowed)?"OFF\n":(palette?"YES\n":"NO\n"));
  661.             FPuts(fh,"ZOOM=");
  662.             FPuts(fh,(!ZoomAllowed)?"OFF\n":(Zoom?"YES\n":"NO\n"));
  663.             FPuts(fh,"OPENMODE=");
  664.             switch (OpenMode) {
  665.             case OPEN_ILBM_IF_ILBM:
  666.                 FPuts(fh,"IFILBM\n");
  667.                 break;
  668.             case OPEN_ILBM_ALWAYS:
  669.                 FPuts(fh,"ALWAYS\n");
  670.                 break;
  671.             case OPEN_REMAP:
  672.                 FPuts(fh,"REMAP\n");
  673.                 break;
  674.             case OPEN_OPAL:
  675.                 FPuts(fh,"OPAL\n");
  676.                 break;
  677.             case OPEN_ILBM_IF_COLOURS:
  678.             default:
  679.                 FPuts(fh,"IFCOLOURS\n");
  680.                 break;
  681.             }
  682.             if (*ScreenName) {
  683.                 FPuts(fh,"PUBSCREEN=");
  684.                 FPuts(fh,ScreenName);
  685.                 FPuts(fh,"\n");
  686.             }
  687.             else {
  688.                 FPuts(fh,";PUBSCREEN=\n");
  689.             }
  690.             if (*CustomName) {
  691.                 FPuts(fh,"CUSTOMMODE=");
  692.                 FPuts(fh,CustomName);
  693.                 FPuts(fh,"\n");
  694.             }
  695.             else {
  696.                 FPuts(fh,";CUSTOMMODE=\n");
  697.             }
  698.             sprintf(buffer,"CUSTOMDEPTH=%ld\n",CustomDepth);
  699.             FPuts(fh,buffer);
  700.             FPuts(fh,"PREVIEW=");
  701.             FPuts(fh,PreviewScript);
  702.             FPuts(fh,"\n");
  703.             FPuts(fh,"HELP=");
  704.             FPuts(fh,GHelp?"YES\n":"NO\n");
  705.             // Save all prefs settings
  706.             FPuts(fh,";Prefs parameters\n");
  707.             FPuts(fh,"CREATEICONSP=");
  708.             FPuts(fh,CreateIconsP?"YES\n":"NO\n");
  709.             FPuts(fh,"KEEPSETTINGS=");
  710.             FPuts(fh,KeepSettings?"YES\n":"NO\n");
  711.             // Save all render settings
  712.             FPuts(fh,";TSMorph-render parameters\n");
  713.             FPuts(fh,"CREATEICONSR=");
  714.             FPuts(fh,CreateIconsR?"YES\n":"NO\n");
  715.             sprintf(buffer,"DX=%ld\n",DX);
  716.             FPuts(fh,buffer);
  717.             sprintf(buffer,"DY=%ld\n",DY);
  718.             FPuts(fh,buffer);
  719.             FPuts(fh,"LOADSCRIPT=");
  720.             FPuts(fh,LoadScript);
  721.             FPuts(fh,"\n");
  722.             FPuts(fh,"PRESCRIPT=");
  723.             FPuts(fh,PreScript);
  724.             FPuts(fh,"\n");
  725.             FPuts(fh,"POSTSCRIPT=");
  726.             FPuts(fh,PostScript);
  727.             FPuts(fh,"\n");
  728.             sprintf(buffer,"DEPTH=%ld\n",Depth);
  729.             FPuts(fh,buffer);
  730.             sprintf(buffer,"MODE=%ld\n",RenderMode);
  731.             FPuts(fh,buffer);
  732.             FPuts(fh,"SAVEFORMAT=");
  733.             switch (SaveFormat) {
  734.             case MI_OPAL24:
  735.                 FPuts(fh,"OPAL24\n");
  736.                 break;
  737.             case MI_OPAL24T:
  738.                 FPuts(fh,"OPAL24T\n");
  739.                 break;
  740.             case MI_OPAL24F:
  741.                 FPuts(fh,"OPAL24F\n");
  742.                 break;
  743.             case MI_OPAL24FT:
  744.                 FPuts(fh,"OPAL24FT\n");
  745.                 break;
  746.             case MI_JPEG:
  747.                 FPuts(fh,"JPEG\n");
  748.                 break;
  749.             case MI_JPEGT:
  750.                 FPuts(fh,"JPEGT\n");
  751.                 break;
  752.             case MI_PBM:
  753.                 FPuts(fh,"PPM\n");
  754.                 break;
  755.             case MI_BW16:
  756.                 FPuts(fh,"BW16\n");
  757.                 break;
  758.             case MI_BW256:
  759.                 FPuts(fh,"BW256\n");
  760.                 break;
  761.             case MI_HAM6:
  762.                 FPuts(fh,"HAM6\n");
  763.                 break;
  764.             case MI_HAM8:
  765.                 FPuts(fh,"HAM8\n");
  766.                 break;
  767.             case MI_DCTV3:
  768.                 FPuts(fh,"DCTV3\n");
  769.                 break;
  770.             case MI_DCTV4:
  771.                 FPuts(fh,"DCTV4\n");
  772.                 break;
  773.             case MI_ILBM24:
  774.             default:
  775.                 FPuts(fh,"ILBM24\n");
  776.                 break;
  777.             }
  778.             sprintf(buffer,"QUALITY=%ld\n",Quality);
  779.             FPuts(fh,buffer);
  780.             if (*ScreenNameR) {
  781.                 FPuts(fh,"PUBSCREENR=");
  782.                 FPuts(fh,ScreenNameR);
  783.                 FPuts(fh,"\n");
  784.             }
  785.             else {
  786.                 FPuts(fh,";PUBSCREENR=\n");
  787.             }
  788.             FPuts(fh,"ANTIALIAS=");
  789.             FPuts(fh,AntiAlias?"YES\n":"NO\n");
  790.             FPuts(fh,"INTEGER=");
  791.             FPuts(fh,Integer?"YES\n":"NO\n");
  792.             // If want to save prefs Icon
  793.             if (CreateIconsP) {
  794.                 if (MyDiskObject = GetDiskObject(ifilename)) {
  795.                     // Icon already present so do not overwrite
  796.                     FreeDiskObject(MyDiskObject);
  797.                 }
  798.                 else {
  799.                     // Try and get an icon and write it
  800.                     if ((MyDiskObject = GetDiskObject("ENV:TSMorph/def_prefs")) ||
  801.                         (MyDiskObject = GetDiskObject("ENV:SYS/def_prefs")) ||
  802.                          (MyDiskObject = GetDefDiskObject(WBPROJECT))) {
  803.                         PutDiskObject(ifilename,MyDiskObject);
  804.                         FreeDiskObject(MyDiskObject);
  805.                     }
  806.                 }
  807.             }
  808.             // try and close the file
  809.             if (!Close(fh)) {
  810.                 ok = FALSE;
  811.             }
  812.         }
  813.         else {
  814.             ok = FALSE;
  815.         }
  816.     }
  817.     // enable the windows and display error if required
  818.     EnableWindows();
  819.     if (!ok) {
  820.         Error("Error Saving Settings '%s'","OK",ifilename,HE_SaveSettings);
  821.     }
  822. }
  823.  
  824. /* Load the current settings
  825.  * Parameters: filename - filename to load from
  826.  *                        or NULL for requester
  827.  */
  828. void
  829. LoadSettings(char *filename) {
  830.     BPTR    fh;                        // file handle
  831.     int     kount = 0;                // count of lines
  832.     int     kount1 = 0;                // index
  833.     BOOL    ok = TRUE;                // Still ok?
  834.     char    string[65];                // record buffer
  835.     char    *ifilename = NULL;    // actual filename
  836.     // if no file name then show requester
  837.     if (!filename) {
  838.         if (GetAFile("TSMorph.prefs","Load Settings",0)) {
  839.             ifilename = TempFilename;
  840.         }
  841.     }
  842.     else {
  843.         ifilename = filename;
  844.     }
  845.     // if we now have a file name...
  846.     // see Args.c MyArgArrayInit() for more info
  847.     if (ifilename) {
  848.         if (ArgArraySettings) {
  849.             FreeVec(ArgArraySettings);
  850.             ArgArraySettings = NULL;
  851.         }
  852.         if (fh = Open(ifilename,MODE_OLDFILE)) {
  853.             // If we have found a file the relevant lines
  854.             while (FGets(fh,string,64)) {
  855.                 if ((string[0] != '\n') &&
  856.                      (string[0] != ';')) {
  857.                     ++kount;
  858.                 }
  859.             }
  860.             Close(fh);
  861.             if (fh = Open(ifilename,MODE_OLDFILE)) {
  862.                 // Allocate memory for settings from file pointers
  863.                 if (ArgArraySettings = AllocVec((kount+1) * sizeof(UBYTE *),MEMF_CLEAR)) {
  864.                     // Read in all settings
  865.                     while (FGets(fh,string,64) &&
  866.                              (kount1 < kount)) {
  867.                         // remove newline
  868.                         string[strlen(string)-1] = '\0';
  869.                         // ignore blank and comment lines
  870.                         if (string[0] && (string[0]!=';')) {
  871.                             // Clone settings in memory
  872.                             ArgArraySettings[kount1] = strdup(string);
  873.                             ++kount1;
  874.                         }
  875.                     }
  876.                     // reset up the new settings
  877.                     InitParams(TRUE);
  878.                 }
  879.                 else {
  880.                     ok = FALSE;
  881.                 }
  882.                 Close(fh);
  883.             }
  884.             else {
  885.                 ok=FALSE;
  886.             }
  887.         }
  888.         else {
  889.             ok=FALSE;
  890.         }
  891.     }
  892.     if (!ok) {
  893.         Error("Error Loading Settings '%s'","OK",ifilename,HE_LoadSettings);
  894.     }
  895. }
  896.